<%--
  Created by IntelliJ IDEA.
  User: Distance
  Date: 2021/10/25
  Time: 17:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<div id="page_nav">
    <c:if test="${requestScope.book.pageNo>1}">
        <a href="${requestScope.book.url}&pageNo=1">首页</a>
        <a href="${requestScope.book.url}&pageNo=${requestScope.book.pageNo-1}">上一页</a>
    </c:if>


    <%--			<a href="manager/bookServlet?action=page&pageNo=${requestScope.book.pageNo-1}">${requestScope.book.pageNo-1}</a>--%>
    <%--			[${requestScope.book.pageNo}]--%>
    <%--			<a href="manager/bookServlet?action=page&pageNo=${requestScope.book.pageNo+1}">${requestScope.book.pageNo+1}</a>--%>
    <c:choose>
        <%--					总页数小于5 可以用下面的  或者总页数大于5 显示1 2 3--%>
        <%--				情况1总页数大于5 显示1 2 3 页数一直是12345：--%>
        <c:when test="${requestScope.book.pageNo<=5}">
            <c:set var="begin" value="1"/>
            <c:set var="end" value="${requestScope.book.pageTotal}"/>
            <%--					优化代码 减少代码的冗余--%>
            <%--					<c:forEach begin="1" end="5" var="i">--%>
            <%--						<c:if test="${requestScope.book.pageNo == i}">--%>
            <%--							<a href="manager/bookServlet?action=page&pageNo=${i}">[${i}]</a>--%>
            <%--						</c:if>--%>
            <%--						<c:if test="${requestScope.book.pageNo != i}">--%>
            <%--							<a href="manager/bookServlet?action=page&pageNo=${i}">${i}</a>--%>
            <%--						</c:if>--%>
            <%--					</c:forEach>--%>
        </c:when>
        <%--总页数大于10 --%>
        <%--情况2：显示页面的最后三个页面 比如10 就是 8 9 10--%>
        <c:when test="${requestScope.book.pageNo> requestScope.book.pageTotal-3}">
            <c:set var="begin" value="${requestScope.book.pageTotal-4}"/>
            <c:set var="end" value="${requestScope.book.pageTotal}"/>
            <%--					优化代码 减少代码的冗余--%>
            <%--					<c:forEach begin="requestScope.book.pageTotal-4" end="requestScope.book.pageTotal}" var="i">--%>
            <%--						<c:if test="${requestScope.book.pageNo == i}">--%>
            <%--							<a href="manager/bookServlet?action=page&pageNo=${i}">[${i}]</a>--%>
            <%--						</c:if>--%>
            <%--						<c:if test="${requestScope.book.pageNo != i}">--%>
            <%--							<a href="manager/bookServlet?action=page&pageNo=${i}">${i}</a>--%>
            <%--						</c:if>--%>
            <%--					</c:forEach>--%>
        </c:when>
        <%--  情况3：3 4 5 6 7 页码范围 当前页面-2 - 当前页面+2--%>
        <c:otherwise>
            <c:set var="begin" value="${requestScope.book.pageNo-2}"/>
            <c:set var="end" value="${requestScope.book.pageNo+2}"/>
            <%--					优化代码 减少代码的冗余--%>
            <%--					<c:forEach begin="requestScope.book.pageNo-2" end="requestScope.book.pageNo+2	}" var="i">--%>
            <%--						<c:if test="${requestScope.book.pageNo == i}">--%>
            <%--							<a href="manager/bookServlet?action=page&pageNo=${i}">[${i}]</a>--%>
            <%--						</c:if>--%>
            <%--						<c:if test="${requestScope.book.pageNo != i}">--%>
            <%--							<a href="manager/bookServlet?action=page&pageNo=${i}">${i}</a>--%>
            <%--						</c:if>--%>
            <%--					</c:forEach>--%>
        </c:otherwise>
    </c:choose>
    <c:forEach begin="${begin}" end="${end}" var="i">
        <c:if test="${requestScope.book.pageNo == i}">
            <a href="${requestScope.book.url}&pageNo=${i}">[${i}]</a>
        </c:if>
        <c:if test="${requestScope.book.pageNo != i}">
            <a href="${requestScope.book.url}&pageNo=${i}">${i}</a>
        </c:if>
    </c:forEach>


    <c:if test="${requestScope.book.pageNo < requestScope.book.pageTotal}">
        <a href="${requestScope.book.url}&pageNo=${requestScope.book.pageNo+1}">下一页</a>
        <a href="${requestScope.book.url}&pageNo=${requestScope.book.pageTotal}">末页</a>
    </c:if>
    共${requestScope.book.pageTotal}页，${requestScope.book.getTotalCount}条记录 到第<input value="${param.pageNo}" name="pn" id="pn_input"/>页
    <input type="button" value="确定" id="searchPageBtn">
    <script>
        $(function (){
            $("#searchPageBtn").click(function (){
                var pageNo = $("#pn_input").val();
                if(pageNo>=1 &&pageNo<=${requestScope.book.pageTotal}){
                    location.href=${requestScope.basePath}"${requestScope.book.url}&pageNo="+pageNo;
                }else {
                    alert("页数错误!");
                    location.href=${requestScope.basePath}"${requestScope.book.url}&pageNo=1";
                }
            });
        });
    </script>
</div>
</div>
